package com.example.device.vm

import com.example.common.view.vm.BaseViewModel
import com.example.device.api.DeviceApiService
import com.example.device.entity.PollingEntity
import com.example.device.model.DeviceRepository
import com.example.device.model.DeviceResultData
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class PollingViewModel @Inject constructor(private val apiService: DeviceApiService):BaseViewModel<DeviceRepository,DeviceResultData<List<PollingEntity>>>(){
    fun getPolling(){
        mViewModelScope.launch (mDispatcher){
            try {
                val result = apiService.getPolling()
                mSuccessLiveData.postValue(result)
            }catch (e:Exception){
                mErrorLiveData.postValue("请求失败:${e.message}")
            }
        }
    }
}